# -*- coding: utf8 -*-

import os
import cx_Oracle
import datetime


def OutputTypeHandler(cursor, name, defaultType, size,
        precision, scale): 
    if defaultType in (cx_Oracle.STRING, cx_Oracle.FIXED_CHAR): 
        return cursor.var(unicode, size, cursor.arraysize)

class BIDbQuery(object):
    """
    jdz oracle 系统
    """

    def __init__(self):
        self.conn = cx_Oracle.connect("jdzpost/jdzpost123@jdzpost")
        self.cursor = self.conn.cursor()

    def close(self):
        self.conn.close()

    def get_year(self, dwid):
        '''获取test'''

        self.cursor.execute("select 单位名称，单位人数，开办邮益宝人数，总资产，营销部门,所属区域,归属部门,归属网点 from 单位明细表 where 单位ID = :dwid", {'dwid': dwid})
        results = []
        for r in self.cursor.fetchall():
            d = dict()
            d['dwmc'] = unicode(r[0], 'utf8')
            d['dwrs'] = r[1]
            d['yybrs'] = r[2]
            d['zzc'] = r[3]
            if r[4] == None:
                d['yxbm'] = ''
            else:   
                d['yxbm'] = unicode(r[4], 'utf8')
            
            if r[5] == None:
                d['ssqy'] = ''
            else:   
                d['ssqy'] = unicode(r[5], 'utf8')

            if r[6] == None:
                d['gsbm'] = ''
            else:   
                d['gsbm'] = unicode(r[6], 'utf8')

            if r[7] == None:
                d['gswd'] = ''
            else:   
                d['gswd'] = unicode(r[7], 'utf8')         

            results.append(d)

        return results



